package com.base.mine;

import android.text.TextUtils;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.commonlib.base.CBaseBarMvpActivity;
import com.base.commonlib.sp.SpUtil;
import com.base.mine.databinding.ActivityChangepwBinding;
import com.base.mine.presenter.ChangePwPresenter;
import com.base.mine.view.ChangePwView;

/**
 * Created by weikailiang on 2019/10/29.
 */

@Route(path = "/changepw/pw")
public class ChangePwActivity extends CBaseBarMvpActivity<ChangePwPresenter> implements ChangePwView{
    @Autowired
    int type;
    private ActivityChangepwBinding mBinding;
    @Override
    protected int getLayoutResource() {
        return R.layout.activity_changepw;
    }

    @Override
    protected void init() {
        super.init();
        mBinding = (ActivityChangepwBinding) mRootBinding;
        mPresenter = new ChangePwPresenter(this,this);
        mPresenter.start();
        setBackNavigation();
        setBarTitle("重置密码");
        if (type==1){
            mBinding.llOriginal.setVisibility(View.GONE);
            mBinding.original.setText("yookey");
        }
    }

    @Override
    protected void start() {
        mBinding.account.setText(SpUtil.getUserAccount());

        mBinding.sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(mBinding.original.getText().toString())){
                    showMes("原密码不能为空");
                    return;
                }
                if (TextUtils.isEmpty(mBinding.newpw.getText().toString())){
                    showMes("新密码不能为空");
                    return;
                }

                if (TextUtils.isEmpty(mBinding.ensurepw.getText().toString())){
                    showMes("确认密码不能为空");
                    return;
                }

                mPresenter.changePw(mBinding.original.getText().toString(),mBinding.newpw.getText().toString(),mBinding.ensurepw.getText().toString(),SpUtil.getUserAccount());
            }
        });
    }
}
